﻿using UnityEngine;
using System.Collections;
using System.IO;
using SevenZip;
using System.Text;
using System;

namespace MyAssetBundles {
    public class MyAssetBundlesUtil {
        public static bool ExtensionEquals (string fileName, string extension)
        {
            string[] first = Path.GetExtension(fileName).Split('.');
            string[] second = extension.Split('.');
            return string.Equals(first[first.Length - 1], second[second.Length - 1]);
        }

        public static bool IsManifestFile (string fileName)
        {
            return ExtensionEquals(fileName, MyAssetBundlesConfig.ManifestExtension);
        }

        public static string MD5ToString (byte[] arr)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < arr.Length; i++)
            {
                sb.Append(arr[i].ToString("x2"));
            }
            return sb.ToString();
        }

        public static string PathCombine (string pathFirst, string pathSecond, bool isCleanFrontOblique = false)
        {
            return PathNormalize(Path.Combine(pathFirst, pathSecond), isCleanFrontOblique);
        }

        public static string PathNormalize (string path, bool isCleanFrontOblique = false)
        {
            string temp = path.Replace("\\", "/");
            if (isCleanFrontOblique && temp.StartsWith("/")) temp = temp.Remove(0, 1);
            if (temp.EndsWith("/")) temp = temp.Remove(temp.Length - 1, 1);
            return temp;
        }
    }
}
